
const https = require('https'),
      url = require('url'),
      name = process.argv[2];
      log = console.log;
let  addr = 'https://api.github.com/search/repositories?q=user:' + name;
let opt = url.parse(addr);

opt.headers = {
  'User-Agent':'02-get-repos.js'
};

https.get(opt,(res)=>{
  let result = '';

  res.on('data',chunk=>{
    result += chunk.toString('utf8');
  });
  res.on('end',()=>{
    let reps = JSON.parse(result);
    //log('reps',reps);
    log('Total:',reps.items.length);
    log('====================');
    for(let i=0;i<reps.items.length;i++){
      log('%d\t%s',(i+1),reps.items[i].name);
    }
  });
});

